package cn.edu.stu.contorller.common;

import cn.edu.stu.bean.AjaxResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.sql.SQLSyntaxErrorException;

/**
 * @author Karl
 * @Date 2022/12/21 - 21:38
 */
@RestControllerAdvice
public class ExceptionController {

    @ExceptionHandler(SQLSyntaxErrorException.class)
    public AjaxResult handlerSQLSyntaxErrorException(SQLSyntaxErrorException e){
        return AjaxResult.error(e.getMessage());
    }

    @ExceptionHandler(IOException.class)
    public AjaxResult handlerIOException(IOException e){
        return AjaxResult.error(e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public AjaxResult handlerException(Exception e){
        return AjaxResult.error(e.getMessage());
    }
}
